from rich import print

print("Hello, [bold magenta]World[/bold magenta]!", ":mac:", locals())

import os
import sys
from rich.columns import Columns

# directory = os.listdir(sys.argv[1])
directory = os.listdir()
print(Columns(directory))

# Console  ------------------------------------------------------------------------
from rich.console import Console

console = Console()
console.print("-" * 220, " hello world!", style="red")
print("-" * 220, " hello world!")
console.print(
    "Where there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i]way[/i]."
)

test_data = [
    {
        "jsonrpc": "2.0",
        "method": "sum",
        "params": [None, 1, 2, 4, False, True],
        "id": "1",
    },
    {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},
    {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": "2"},
]


def test_log():
    enabled = False
    context = {
        "foo": "bar",
    }
    movies = ["Deadpool", "Rise of the Skywalker"]
    console.log("Hello from", console, "!")
    console.log(test_data, log_locals=True)


test_log()

console.print(":ok: :bad: :pile_of_poo: :thumbs_up: :raccoon:")
# Table  ------------------------------------------------------------------------

from rich.table import Column, Table

table = Table(show_header=True, header_style="bold magenta")
table.add_column("Date", style="dim", width=12)
table.add_column("Title")
table.add_column("Production Budget", justify="right")
table.add_column("Box Office", justify="right")
table.add_row(
    "Dev 20, 2019", "Star Wars: The Rise of Skywalker", "$275,000,000", "$375,126,118"
)
table.add_row(
    "May 25, 2018",
    "[red]Solo[/red]: A Star Wars Story",
    "$275,000,000",
    "$393,151,347",
)
table.add_row(
    "Dec 15, 2017",
    "Star Wars Ep. VIII: The Last Jedi",
    "$262,000,000",
    "[bold]$1,332,539,889[/bold]",
)
console.print(table)

# track --------------------------------------------------------------------------
from rich.progress import track
from time import sleep

for step in track(range(10)):
    print(step)

    sleep(0.1)


# Syntax --------------------------------------------------------------------------
from rich.syntax import Syntax

my_code = '''
def iter_first_last(values: Iterable[T]) -&gt; Iterable[Tuple[bool, bool, T]]:
    """Iterate and generate a tuple with a flag for first and last value."""
    iter_values = iter(values)
    try:
        previous_value = next(iter_values)
    except StopIteration:
        return
    first = True
    for value in iter_values:
        yield first, False, previous_value
        first = False
        previous_value = value
    yield first, True, previous_value
'''
syntax = Syntax(my_code, "python", theme="monokai", line_numbers=True)
console.print(syntax)
